﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using ProjectBase.Core;
using ProjectBase.Mvc.Controllers;

namespace $safeprojectname$.Binding
{
    [TestClass]
    public class BindingTest : TestBase
    {
        [TestMethod]
        public void BindModel_Passed()
        {
            var item = new BindTarget();
            var smart = new SmartBinder();


            var controllerContext = new ControllerContext();
            var bindingContext = new ModelBindingContext
            {
                ValueProvider = new ImportValueProvider(),
                ModelMetadata = ModelMetadataProviders.Current
                    .GetMetadataForType(() => item, typeof(BindTarget)),
            };

            Assert.IsFalse(item.Abc == "Abc");
            Assert.IsFalse(item.Def == "Def");
            Assert.IsFalse(item.Xyz == 123);


            smart.BindModel(controllerContext, bindingContext);

            Assert.IsTrue(item.Abc.IsNotEmpty());
            Assert.IsTrue(item.Def.IsNotEmpty());
            Assert.IsTrue(item.Xyz.Is() & item.Xyz.Value > 0);

            Assert.IsTrue(item.Abc == "Abc");
            Assert.IsTrue(item.Def == "Def");
            Assert.IsTrue(item.Xyz == 123);
        }
    }
}
